package com.thjk.bdf.system.service.impl;

import java.text.SimpleDateFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.thjk.bdf.system.service.LoanService;
import com.thjk.bdf.system.service.controller.BaseController;
import com.thjk.bdf.system.service.dao.BdfPayOutMapper;
import com.thjk.bdf.system.service.request.LoanRequest;
import com.thjk.bdf.system.service.response.LoanResponse;
import com.thjk.loan.management.common.page.TableDataInfo;

@RestController
@RequestMapping("/loan")
public class LoanServiceImpl extends BaseController implements LoanService{

	@Autowired
	private BdfPayOutMapper payOutMapper;
	
	@PostMapping("/list")
	@Override
	public TableDataInfo selectByPage(@RequestBody LoanRequest requset) {
		startPage(requset);
		List<LoanResponse> orders = payOutMapper.selectByPage(requset);
		for (LoanResponse order : orders) {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			if(null != order.getCreateTime())
			order.setPutoutTime(formatter.format(order.getCreateTime()));
			if(null != order.getFpCreateTime()) {
				order.setFpCredateTime(formatter.format(order.getFpCreateTime()));
			}
			order.setFpCreateTime(null);
		}
		return getDataTable(orders);
	}

	@PostMapping("/selectById")
	@Override
	public LoanResponse selectById(Long id) {
		// TODO Auto-generated method stub
		LoanResponse order = payOutMapper.selectById(id);
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		order.setPutoutTime(formatter.format(order.getCreateTime()));
		if(null != order.getFpCreateTime())
		order.setFpCredateTime(formatter.format(order.getFpCreateTime()));
		order.setFpCreateTime(null);
		return order;
	}

	@PostMapping("/selectExport")
	@Override
	public List<LoanResponse> selectExport(@RequestBody LoanRequest request) {
		List<LoanResponse> orders = payOutMapper.selectByPage(request);
		for (LoanResponse order : orders) {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			if(null != order.getCreateTime())
			order.setPutoutTime(formatter.format(order.getCreateTime()));
			if(null != order.getFpCreateTime())
			order.setFpCredateTime(formatter.format(order.getFpCreateTime()));
			order.setFpCreateTime(null);
		}
		return orders;
	}

}
